package org.langqiao.network.java复习题老师给的;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class logon extends JFrame implements ActionListener{
	private JLabel label1;
	private JLabel label2;
	private JTextField text1;
	private JPasswordField text2;
	// JButton button1;
	//private JButton button2;
	public logon()//构造方法
	{
		super("登陆");//窗口名
		JPanel pane=new JPanel();
		this.getContentPane().add(pane);//将面板添加到窗口中
		JLabel label1=new JLabel("用户");
		pane.add(label1);
		JTextField text1=new JTextField();
		pane.add(text1);
		JLabel label2=new JLabel("密码");
		pane.add(label2);
		JPasswordField text2=new JPasswordField();
		pane.add(text2);//文本行中显示的内容就是密码样式 的*
		Button button1=new Button("登陆");
		Button button2=new Button("取消");
		pane.add(button1);
		button1.addActionListener(this);
		pane.add(button2);
		button2.addActionListener(this);
		pane.setLayout(new GridLayout(3,2));//对面板进行网格布局3行2列
		this.setBounds(100,200,250,100);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);//关闭窗口]
		this.setResizable(false);
		this.setVisible(true);
		
		
	}
	public void actionPerformed(ActionEvent e)
	{
		try
		{
			if(e.getActionCommand()=="登陆")
			{
				//System.out.print("你点击了登陆按钮");
				
					char []password=text2.getPassword();//通过getPassword()方法将密码存储在字符数组里
					String user=text1.getText();
					String str=new String(password);//将字符数组转化为字符窜
					String user1="Simon.C";
					String str1="12345";
				
				
				
					if(user.equals(user1)&&str.equals(str1))
					{
						JOptionPane.showMessageDialog(null,"欢迎你，Simon.C");
//						this.setVisible(false);
					}
					else
					{
						JOptionPane.showMessageDialog(null,"用户名或密码错误，请重新输入！");
					}
				
			}
			if(e.getActionCommand()=="取消")
			{
				System.exit(0);
			}
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
	public static void main(String[] args)
	{
		new logon();
	}

}
